﻿using System;

namespace Quail.DbLogger.Task
{
	/// <summary>
	/// Wraps finishing a TestRunTask
	/// </summary>
    public class FinishTestRunTask : QuailDbLoggerEntry
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="FinishTestRunTask"/> class.
        /// </summary>
        /// <param name="testruntaskid">The testruntaskid.</param>
        /// <param name="taskstatus">The taskstatus.</param>
        /// <param name="finishDate">Time the task finished</param>
        public FinishTestRunTask(long testruntaskid, LogStatus taskstatus, DateTime finishDate)
        {
            TaskFinishDate = finishDate;
            TestRunTaskId = testruntaskid;
            TaskStatus = taskstatus;
        }

        private long TestRunTaskId { get; set; }

        private LogStatus TaskStatus { get; set; }

        private DateTime TaskFinishDate { get; set; }

        /// <summary>
        /// Finishes a test run task
        /// </summary>
        /// <param name="dataContext">the context to use</param>
        public override void Store(QuailServices.QuailDataServiceReference.QuailDataServiceClient dataContext)
        {
            dataContext.FinishTestRunTask(TestRunTaskId, (int)TaskStatus, TaskFinishDate);
        }

        /// <summary>
        /// Returns a string representation of the entry for logging purposes
        /// </summary>
        /// <returns>A log string</returns>
        public override string GetLogDetail()
        {
            return string.Format("FinishTestRunTask({0},{1},{2})", TestRunTaskId, TaskStatus, TaskFinishDate);
        }
    }
}
